package utility;

public class TimeMeasure {
	long start=0;
	long stop=0;
	static public final int Ready=0;
	static public final int Busy=1;
	static public final int finish=2;
	int state=TimeMeasure.Ready;
	String marker=null;
	public TimeMeasure(){
		this.marker="TimeMeasure";
		return;
	}
	
	public TimeMeasure(String msg){
		this.marker=msg;
		return;
	}
	
	public Boolean start(){
		if(state==TimeMeasure.Busy)
			return false;
		start=stop=0;
		this.state=TimeMeasure.Busy;
		start = System.currentTimeMillis();
		
		return true;
	}
	
	public Boolean stop(){
		if(state!=TimeMeasure.Busy)
			return false;
		stop = System.currentTimeMillis();
		this.state=TimeMeasure.finish;
		return true;
	}
	
	public long GetResult(){
		if(this.state!=TimeMeasure.finish)
			return -1;
		return stop-start;
	}
	
	public void Output(){
		System.out.println(this.marker+": 実行にかかった時間は " + (stop - start) + " ミリ秒です。");
	}
}
